package edu.mis.test;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;

import edu.mis.model.Blog;
import edu.mis.modules.blog.BlogController;

public class Config extends JFinalConfig {

    public static void main(String[] args) {
        JFinal.start("WebRoot", 8089, "/", 5);
    }

    @Override
    public void configConstant(Constants me) {
    	PropKit.use("dbconfig.txt");
        me.setDevMode(true);
    }

    @Override
    public void configHandler(Handlers me) {

    }

    @Override
    public void configInterceptor(Interceptors me) {
    }

    @Override
    public void configPlugin(Plugins me) {
    	C3p0Plugin C3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
    	me.add(C3p0Plugin);
    	ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
		me.add(arp);
		arp.addMapping("blog", "id", Blog.class);
    }
    
    

    @Override
    public void afterJFinalStart() {
        System.out.println("JFinal Start");
    }

    
    @Override
    public void beforeJFinalStop() {
        System.out.println("JFinal Stop");
    }

    @Override
    public void configRoute(Routes me) {
    	me.add("/blog", BlogController.class);
    }

}
